package com.macaline.framemarker.logic;

import lombok.Data;


@Data
public class Option {

    /**
     * 逻辑关系：并
     */
    public static final Integer LOGIC_AND = 1;
    /**
     * 逻辑关系：且
     */
    public static final Integer LOGIC_OR = 2;

    private Integer logic; // 逻辑 并、或
    private Boolean flag; // 该条结果
    private Option next; // 下一个判断

    /**
     * 构造函数
     * @param logic 逻辑
     * @param isTrue 是否正确
     */
    public Option(Integer logic, Boolean isTrue){
        this.logic = logic;
        this.flag = isTrue;
    }


    /**
     * 添加 且
     * @param isTrue 结果
     */
    public void nextAnd(Boolean isTrue){
        next = new Option(LOGIC_AND, isTrue);
    }

    /**
     * 添加 并
     * @param isTrue
     */
    public void nextOr(Boolean isTrue){
        next = new Option(LOGIC_OR, isTrue);
    }

    /**
     * 是否有下一个元素
     * @return
     */
    public Boolean hasNext(){
        return next != null;
    }

    /**
     * 返回下一个元素
     * @return
     */
    public Option next() throws Exception {
        if(!hasNext()){
            throw new Exception("not have next element!");
        }
        return this.next;
    }

    /**
     * 逻辑是否为并
     * @return
     */
    public Boolean isAnd(){
        return logic == LOGIC_AND;
    }

    /**
     * 逻辑是否为且
     * @return
     */
    public Boolean isOr(){
        return logic == LOGIC_OR;
    }

}
